package com.sservice.web.controller.pc;

import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.base.entity.dto.Pagination;
import com.sservice.base.entity.dto.QueryCondition;
import com.sservice.model.entity.UserWx;
import com.sservice.model.vo.AdsVo;
import com.sservice.model.vo.InfoVo;
import com.sservice.service.service.IAdsService;
import com.sservice.service.service.IInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 小程序、微官网接口
 */
@Controller
@RequestMapping("/min")
public class MinPcController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IAdsService service;
    @Autowired
    SalePersonPcController salePersonPcController;

    /**
     * 登录用户
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/current", method = RequestMethod.POST)
    public BaseResult<UserWx> create(HttpSession session) {
        return salePersonPcController.current(session);
    }

    @Autowired
    IInfoService iInfoService;

    /**
     * 首页统计
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/count", method = RequestMethod.GET)
    public BaseResult<Object> count(QueryCondition queryCondition) {
        InfoVo infoVo = new InfoVo();
        infoVo.setType1(6);//在线咨询
        infoVo.setDateStart(queryCondition.getDateStart());
        infoVo.setDateEnd(queryCondition.getDateEnd());
        int askNum = iInfoService.countPlainByPage(infoVo);
        Map countObj = new HashMap();
        countObj.put("countAsk", askNum);
        BaseResult<Object> res = new BaseResult(true, countObj);
        return res;
    }

    /**
     * 在线咨询
     *
     * @param queryCondition
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/infos", method = RequestMethod.GET)
    public ListResult<Object> infus(QueryCondition queryCondition) {
        InfoVo infoVo = new InfoVo();
        infoVo.setType1(6);//在线咨询
        infoVo.setDateStart(queryCondition.getDateStart());
        infoVo.setDateEnd(queryCondition.getDateEnd());
        List<InfoVo> list = iInfoService.queryPlainByPage(infoVo);
        int numbers = iInfoService.countPlainByPage(infoVo);
        ListResult<Object> res = new ListResult(true, list);
        res.setPage(new Pagination(queryCondition.getPage(), numbers, queryCondition.getSize()));
        return res;
    }


    /***
     * 分页查询
     * @param arg
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ListResult query(AdsVo arg) {
        List<AdsVo> list = service.selectAll(arg);
        ListResult res = new ListResult(true, list);
        return res;
    }
}
